/**
 * Created by weng on 2017/8/16.
 */

var data_temp = {};
var  temp_page_size= 15;

/**
 * 获取预约名单
 * @param info
 */
var homeAccountList = function () {
    console.log("获取信息");
    var obj = {};
    var phone = $("#phone").val();
    if(phone)
        obj.phone = phone;
    $.ajax({
        url:'/hospital/getBusOrder',
        type:'post',
        dataType:'json',
        data:obj,
        success:function(data) {
            if (data.code != 200) {
                alert("查询错误");
                return;
            } else {
                if(data.info.length > 0){
                    data_temp = data.info
                    var temp_teble_info = data_temp.slice(0 , temp_page_size);
                    createPageMin(temp_page_size, 5, Math.ceil(data_temp.length), data_temp);
                    showTableInfo(temp_teble_info);
                }

            }
        }
    });
};



function createPageMin(pageSize, buttons, total,data_temp) {
    $("#pagination").empty();
    $('#pagination').Paging({pagesize:pageSize,count:total,toolbar:true,pageSizeList:[temp_page_size],
        callback:function(page,size,count){
            page = page - 1;
            var temp_teble_info = data_temp.slice(page  * size ,page * pageSize + size);
            showTableInfo(temp_teble_info);
        }});
}


function showTableInfo(data_arr){
    var html = "";
    var thead = $('#taccountList thead');
    var tbody = $('#taccountList tbody');
    tbody.empty();
    thead.empty();
    var htmlHead = "<tr>"
        + "<th>约车时间：</th>"
        + "<th>约车班次：</th>"
        + "<th>约车地点：</th>"
        + "<th>约车号码：</th>"
        + "<th>约车人数：</th>"

        + "<th>探望亲属住院号：</th>"
        + "<th>探望亲属姓名：</th>"
        + "<th>状态：</th>"

        + "</tr>"
    htmlHead = $(htmlHead);
    thead.append(htmlHead);

    for(var i in data_arr){
        var flag = '正常';
        if(data_arr[i].status == 1){
            flag = '取消预约';
        }
        html += '<tr>' +
            '<th  id="time'+ data_arr[i].id +'">'+ moment(data_arr[i].time).format("YYYY-MM-DD") + '</th>' +
            '<th  id="orderTime'+ data_arr[i].id +'">'+  data_arr[i].orderTime + '</th>' +
            '<th  id="orderTime'+ data_arr[i].id +'">'+  data_arr[i].address + '</th>' +
            '<th  id="phone'+ data_arr[i].id +'">'+  data_arr[i].phone + '</th>' +
            '<th  id="phone'+ data_arr[i].num +'">'+  data_arr[i].num + '</th>' +

            '<th  id="'+ data_arr[i].id +'">'+  data_arr[i].id + '</th>' +
            '<th  id="'+ data_arr[i].id +'">'+  data_arr[i].name + '</th>' +
            '<th  id="flag'+ data_arr[i].id +'">'+  flag + '</th>' +

            '</tr>'
    }
    var tr = $(html);
    tbody.append(tr);
}

